(setf d (make-hash-table :test 'eq))
(setf (gethash 1 d) 0)

(defun collatz (n)
  (cond
   ((= 1 n) nil)
   ((evenp n) (/ n 2))
   (t (1+ (* 3 n)))))

(defun hashed-collatz (n d)
  (if (gethash n d) (gethash n d)
	(let ((s (1+ (hashed-collatz (collatz n) d))))
	  (setf (gethash n d) s)
	  (format t "n:~a s:~a~%" n s)
	  s)))

(defun populate-table (d)
  (dotimes (i 1000000) (hashed-collatz (1+ i) d)))

(defun nil2num (n)
  (if (null n) 0 n))

(defun get-max (d)
  (do* ((i 1 (1+ i))
		(max 0 (if (>= (nil2num (gethash max d)) (nil2num (gethash i d)))
				   max i)))
	  ((>= i 1000000) max)
	(format t "max:~a i:~a~%" max i)))
